
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;


public class BuffEffect_Shield : BaseBuffModule
{
    private bool _is_first_be_hurt;

    public bool is_first_be_hurt
    {
        get => card_comp.be_attack_times == 0;
    }

    public CardController card_comp = null;
    public void reset_is_first_be_hurt()
    {
        // BdPackage.BdUtils.log("=== on BuffEffect_Shield.reset_is_first_be_hurt === card_name:", card_comp.card_data.card_name);
        card_comp.btn_active_shield();
        // is_first_be_hurt = true;
        card_comp.be_attack_times = 0;
    }
    
    public void break_shield()
    {
        BdPackage.BdUtils.log("=== on BuffEffect_Shield.break_shield ===");
        card_comp.btn_break_shield_animation();
        
        // is_first_be_hurt = false;
    }
    
    public override void Apply(BuffInfo buffInfo, DamageInfo damageInfo = null)
    {
        BdPackage.BdUtils.assert(buffInfo != null);
        BdPackage.BdUtils.assert(buffInfo.creator != null);
        BdPackage.BdUtils.assert(buffInfo.target != null);

        // BdPackage.BdUtils.log("=== on BuffEffect_Shield ===");

        if (damageInfo == null)
        {
            reset_is_first_be_hurt();
            return;
        }
        
        if (!is_first_be_hurt)
            return;
        
        var card = buffInfo.target.GetComponent<CardController>();
        if (!card.is_equal(damageInfo.target))
            return;
        
        if (damageInfo.damage > 0)
        {
            damageInfo.damage = 0;
            break_shield();
        }
    }
}
